﻿using ExitGames.Client.Photon;
using Photon.Pun;
using System;
using UnityEngine;
using UnityEngine.UI;

public class EndUI : MonoBehaviour 
{
    public GameObject WriteWin;
    public GameObject BlackWin;
    public GameObject Dogfall;
    public Button restartGame;
    private ChessController chessController;
    void Awake()
    {
        WriteWin = transform.Find("WriteWin").gameObject;
        BlackWin = transform.Find("BlackWin").gameObject;
        Dogfall = transform.Find("Dogfall").gameObject;
        chessController = GameObject.FindObjectOfType<ChessController>();
        restartGame = transform.Find("restart").GetComponent<Button>();
        restartGame.onClick.AddListener(() => { chessController.SetGameState(GameState.Ready);
            Hashtable table = new Hashtable();
            table.Add("步子",ChessType.Write);
            PhotonNetwork.CurrentRoom.SetCustomProperties(table);
        });
        ChessController.win += WinShowUI;
        gameObject.SetActive(false);

    }
    void Start()
    {
       
    }

    public void WinShowUI(ChessType obj)
    {
        Debug.Log("WinShowUI");
        switch (obj)
        {
            case ChessType.Write:
                
                WriteWin.SetActive(true);
                break;
            case ChessType.Black:
                BlackWin.SetActive(true);
                break;
            default:
                break;
        }
        gameObject.SetActive(true);
    }
}